package com.ruoyi.blog.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.blog.pojo.AuthUser;
import org.springframework.security.core.Authentication;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

public class SaveUseInfo {
    public static void saveUserInfo(Map<String, Object> map, HttpServletRequest request,
                                    Authentication authentication, HttpSession session, AuthUser user) {
        String username = UserInfoUtil.getUsername(authentication);
        QueryWrapper<AuthUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        if (user!=null) {
            session.setAttribute("username", username);
            map.put("username", username);
            // Y会员用户 N普通用户 A管理员可见 B员工可见
            String isVip = user.getIsVip();
            switch (isVip) {
                case "Y":
                    map.put("level", "会员用户");
                    break;
                case "N":
                    map.put("level", "普通用户");
                    break;
                case "A":
                    map.put("level", "管理员");
                    break;
                case "B":
                    map.put("level", "员工用户");
                    break;
                default:
                    map.put("level", "未知用户");
            }

            map.put("mobile", user.getMobile());
            map.put("address", user.getAddress());
            map.put("email", user.getEmail());
            map.put("images", user.getHeadImages());
            map.put("vip", user.getIsVip());
        }
        session.setAttribute("name", username);
        map.put("name", username);
    }
}
